package com.lzm.back.common;

/**
 * 统一返回包装类
 */
public class MyResult {
    private String code;
    private String msg;
    private Object data;

    public static MyResult success() {
        MyResult result = new MyResult();
        result.setCode("200");
        result.setMsg("请求成功");

        return result;
    }

    public static MyResult success(Object data) {
        MyResult result = success();
        result.setData(data);

        return result;
    }

    public static MyResult error() {
        MyResult result = new MyResult();
        result.setCode("500");
        result.setMsg("系统失败");

        return result;
    }


    public static MyResult error(String code, String msg) {
        MyResult result = new MyResult();
        result.setCode(code);
        result.setMsg(msg);

        return result;
    }

    public static MyResult error(Object data) {
        MyResult result = error();
        result.setData(data);

        return result;
    }


    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "MyResult{" +
                "code='" + code + '\'' +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                '}';
    }
}
